package com.wjk.StuManager.Dao;

import com.wjk.StuManager.Domain.Student;

public class StuDao {
    static Student[] stus = new Student[5];

    public Student[] findAllStu() {
        return stus;
    }

    public Boolean addStu(Student stu) {
        int index = -1;
        for (int i = 0; i < stus.length; i++) {
            if (stus[i] == null) {
                index = i;
            }
        }
        if (index == -1) {
            return false;
        } else {
            stus[index] = stu;
            return true;
        }
    }

    public void delStuById(String delId) {
        int index = getIndex(delId);
        stus[index] = null;
    }

    private int getIndex(String id) {
        int index = -1;
        for (int i = 0; i < stus.length; i++) {
            Student stu = stus[i];
            if (stu != null && stu.getId().equals(id)) {
                index = i;
            }
        }
        return index;
    }

    public void updateStu(String updateId, Student stu) {
        int index = getIndex(updateId);
        stus[index]=stu;
    }
}
